package hk.m4s.lr.repair.test.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import hk.m4s.lr.repair.test.R;
import hk.m4s.lr.repair.test.model.CommonToolModel;
import hk.m4s.lr.repair.test.model.MyToolModel;

/**
 * Created by qi.wang on 2017/3/16.
 */

public class MyToolKitListAdapter extends BaseAdapter{
    List<MyToolModel> list=new ArrayList<>();
    Context context;
    LayoutInflater inflater;

    public MyToolKitListAdapter(Context context, List<MyToolModel> data){
        this.context=context;
        this.list=data;
        inflater=LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder=null;
        if(convertView==null){
            holder=new ViewHolder();
            convertView=inflater.inflate(R.layout.list_item_mytoolkit,parent,false);
            holder.toolkit_num=(TextView) convertView.findViewById(R.id.toolkit_num);
            holder.equ_types=(TextView)convertView.findViewById(R.id.equ_types);
            convertView.setTag(holder);
        }else{
            holder= (ViewHolder) convertView.getTag();
        }

        MyToolModel deviceModel = list.get(position);
            try {
                holder.equ_types.setText(deviceModel.getTeamName());
                holder.toolkit_num.setText(deviceModel.getUserName());

            } catch (Exception e) {
                e.printStackTrace();
            }

        return convertView;
    }

    public static class ViewHolder{
        TextView toolkit_num;
        TextView equ_types;

    }
}
